from django.shortcuts import render
from django.http import HttpResponse
from .forms import Addbook


def index(request):
    return HttpResponse('index')


def add_book(request):
    form = Addbook(request.POST)
    if form.is_valid():
        name = form.cleaned_data.get('name')
        page = form.cleaned_data.get('page')
        phone = form.cleaned_data.get('phone')
        print(name, page, phone)
        form.save()
        return HttpResponse('ok')
    else:
        print(form.errors.get_json_data())
        return HttpResponse('not ok')
